package com.mms.util;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionManager;

public class MyBatisUtilsPlus {
	// 这是一个静态单例
	private static SqlSessionManager sqlSessionManager;

	// 在MyBatisUtils类被JVM加载时，static代码块仅执行一次
	static {
		try {
			String resource = "mybatis-config.xml";
			InputStream inputStream = Resources.getResourceAsStream(resource);
			sqlSessionManager = SqlSessionManager.newInstance(inputStream);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static SqlSessionManager getSqlSessionManager() {
		return sqlSessionManager;
	}
	
	public static <Mapper> Mapper getMapper(Class<Mapper> mapperClass) {
		return sqlSessionManager.getMapper(mapperClass);
	}

}
